package com.example.congfig;


import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.convert.DataSizeUnit;
import org.springframework.boot.convert.DurationFormat;
import org.springframework.boot.convert.DurationUnit;
import org.springframework.stereotype.Component;
import org.springframework.util.unit.DataSize;
import org.springframework.util.unit.DataUnit;
import org.springframework.validation.annotation.Validated;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import java.time.Duration;
import java.time.temporal.ChronoUnit;

@Component
@Data
@ConfigurationProperties("servers")
// 数据校验注解
@Validated
public class ServerConfig {
    private String serverName;
    @Max(value = 8888,message = "最大值不能超过8888！ The maximum value cannot exceed 8888！")
    @Min(value = 0,message = "最小值不能低于0！ Minimum value cannot be lower than 0！")
    private int port;
    private String ip;
    @DurationUnit(ChronoUnit.SECONDS)
    private Duration serverTimeout;

    @DataSizeUnit(DataUnit.MEGABYTES)
    private DataSize dataSize;

    private String password;

}
